﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Database;
public partial class admin_ThemSP : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var pm = new checkLogin();
        pm.redirectToLoginPage();
 
        if (!Page.IsPostBack)
            {                
                    if (Session["tenkh"] == "Amin")
                    {
                        Response.Redirect("Login.aspx");
                    }
                    else
                    {
                        ddlMaHangSX.DataSource = HangSX.DSMaHSX().Tables[0];
                        ddlMaHangSX.DataTextField = "tenhang";
                        ddlMaHangSX.DataValueField = "mahangsx";
                        ddlMaHangSX.DataBind();

                        DDLLoaiMayTinh.DataSource =LoaiMayTinh.DSMaLoaiMT().Tables[0];
                        DDLLoaiMayTinh.DataTextField = "tenloai";
                        DDLLoaiMayTinh.DataValueField = "maloai";
                        DDLLoaiMayTinh.DataBind();
                    }
                
                
            }

        }

        protected void btThem_Click(object sender, EventArgs e)
        {           
            int loaimt = int.Parse(DDLLoaiMayTinh.SelectedValue.ToString());
            string hinhanh;
            if (!String.IsNullOrEmpty(UpLoadHinhAnh.FileName))
            {
                String path = "~/images/" + UpLoadHinhAnh.FileName;
                UpLoadHinhAnh.SaveAs(MapPath(path));
                hinhanh = UpLoadHinhAnh.FileName.ToString();
            }
            else
            {
                hinhanh = "no_image.jpg";
            }
            float giaban =float.Parse(txtGiaBan.Text);
            int soluong = int.Parse(txtSoLuong.Text);           
            int mahangsx = int.Parse(ddlMaHangSX.SelectedValue.ToString());
            bool hienthi;
            if (rbCo.Checked == true)
            {
                hienthi = true;
            }
            else
            {
                hienthi = false;
            }
            MayTinh mt = new MayTinh();
            mt.ThemMT(this.txtTenMay.Text, giaban, soluong, mahangsx, this.txtMoTa.Text, loaimt, hinhanh,hienthi);
            Response.Redirect("DanhsachMT.aspx");

        }

        protected void btCancel_Click(object sender, EventArgs e)
        {           
            
                txtTenMay.Text = "";
                txtGiaBan.Text = "";
                txtSoLuong.Text = "";
                txtMoTa.Text = "";            
        }
    
    
}
